package com.forum.controller;

import com.forum.common.api.CommonResult;
import com.forum.model.vo.AnnouncementVO;
import com.forum.model.vo.ActiveUserVO;
import com.forum.model.vo.PostVO;
import com.forum.service.HomeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "首页接口")
@RestController
@RequestMapping("/home")
@RequiredArgsConstructor
@Slf4j
public class HomeController {

    private final HomeService homeService;

    @Operation(summary = "获取热门帖子")
    @GetMapping("/hot-posts")
    public CommonResult<List<PostVO>> getHotPosts() {
        log.info("请求获取热门帖子");
        List<PostVO> posts = homeService.getHotPosts();
        log.info("返回热门帖子，数量: {}", posts.size());
        return CommonResult.success(posts);
    }

    @Operation(summary = "获取最新帖子")
    @GetMapping("/latest-posts")
    public CommonResult<List<PostVO>> getLatestPosts() {
        log.info("请求获取最新帖子");
        List<PostVO> posts = homeService.getLatestPosts();
        log.info("返回最新帖子，数量: {}", posts.size());
        return CommonResult.success(posts);
    }

    @Operation(summary = "获取公告列表")
    @GetMapping("/announcements")
    public CommonResult<List<AnnouncementVO>> getAnnouncements() {
        log.info("请求获取公告列表");
        List<AnnouncementVO> announcements = homeService.getAnnouncements();
        log.info("返回公告列表，数量: {}", announcements.size());
        return CommonResult.success(announcements);
    }

    @Operation(summary = "获取活跃用户")
    @GetMapping("/active-users")
    public CommonResult<List<ActiveUserVO>> getActiveUsers() {
        log.info("请求获取活跃用户");
        List<ActiveUserVO> users = homeService.getActiveUsers();
        log.info("返回活跃用户，数量: {}", users.size());
        return CommonResult.success(users);
    }
} 